Home | ... | Raspberry Pi Webserver Setup
Charles Varvayanis Logo
Charles Varvayanis
Computer and Communication Systems
Since 1990
(209) 586-3782
charles@varvayanis.com
Charles Varvayanis Logo

Raspberry Pi Webserver Setup

Step-by-step instructions for setting up a simple and reliable webserver hosting multiple websites with HTTP, HTTPS, SSH, FTP, VNC and TeamViewer

These procedures apply to Raspberry Pi 5, 4 or 3 with Raspberry Pi OS (64-Bit), (32-Bit) or (Legacy, 32-Bit) with or without the webserver, HTTPS, SSH, FTP, VNC and/or TeamViewer.


General Notes


1. The procedures below are optomized for setting up a webserver with HTTP and HTTPS hosting multiple websites on a Raspberry Pi 5, 4 or 3 with Raspberry Pi OS (64-Bit), (32-Bit) or (Legacy, 32-Bit) connected via Ethernet.  Management connectivity is provided via SSH, TeamViewer, VNC and FTP.  Notably, a firewall is not included.

2. If the webserver needs to be publically accessible from the Internet:  The Internet connection must have a Public IP address.  Note:  Certain ISPs such as StarLink do not and can not supply Public IP Addresses on thier standard Internet circuits.  If a router is between the Internet and Raspberry Pi, it must be configured to pass HTTP, HTTPS, SSH and FTP traffic as appropriate from the public IP Address to the Raspberry Pi's local IP Address.  A Domain Name must be owned by the end user and a Public DNS Server must be configured to have an "A" record or "CNAME" record pointing to the Public IP Address of the Raspberry Pi webserver.  If the Public IP address is Dynamic, a DDNS service such as noip.com can be employed and a CNAME record set up in the Public DNS Server using the hostname setup in the DDNS service.  Alternatively, a hostname name setup in a DDNS server can be used directly as the URL for the website.

3. Internet access during setup:  Many of the steps below assume and require the target Raspberry Pi is connected to a network with access to the Internet and a DHCP server on the network configured for DHCP clients to access the Internet.  This is a standard and/or default configuration for most networks, so in most cases nothing additional will need to be done.

4. Firewall:  This implementation assumes the Raspberry Pi will be isolated and behind a quality Firewall and does not implement a firewall running on the Raspberry Pi.  If it is not isolated and behind a firewall, it may be wise to consider running a firewall such as the Ubuntu UFW firewall on the Raspberry Pi.  Here are three articles discussing the Ubuntu UFW firewall and there are many more:
  https://help.ubuntu.com/community/UFW
  https://pimylifeup.com/raspberry-pi-ufw
  https://notes.leetdev.net/ubuntu/apache-server-configuration/installing-apache-on-ubuntu-18.04-with-multiple-domains-or-leetdev

5. Management Connectivity Options:  Certain Connectivity options below can be selectively omitted by not implementing the steps in any of these sections below:  "Install and configure TeamViewer", "Configure and Enable VNC", "Install and configure the FTP server - VSFTP".  SSH can be omitted while configuring the Raspberry Pi Imager as in the "Load Raspberry Pi OS onto a Micro SD Card" section below, after choosing the DEVICE, OS and STORAGE then clicking NEXT, EDIT SETTINGS and selecting the SERVICES tab, then unchecking "Enable SSH".  The rest of the procedure should be followed as appropriate for the required needs.

6. HTTP and HTTPS Webserver Options:  The steps below are for implementing a webserver with both HTTP and HTTPS.  If the needs require HTTP only and not HTTPS.  the system can be simplified by omitting and not implementing the steps in the section "Setup HTTPS using Let's Encrypt Certificates and Certbot" below.

7. No Webserver Option:  The steps below are for implementing a webserver with both HTTP and HTTPS.  If the need is simply to get a Raspberry Pi up and running for some other application, the system can be further simplified by omitting and not implementing the steps in the sections below:  "Install and configure the Webserver - Apache 2" and "Setup HTTPS using Let's Encrypt Certificates and Certbot".


Notice about updates, upgrades and installations failing due to repository or network congestion or outages


Occasionally updates, upgrades and installations fail due to repository or network congestion or outages.  Sometimes there is an appropriate message saying as much, sometimes a missing file is reported, and sometimes there is just a failure message without an explanation.  When this occurs, simply run the command again.  If that does not solve the issues immediately, try again later.



Download and Install the Raspberry Pi Imager onto a PC or other computer


Download the Raspberry Pi Imager

https://www.raspberrypi.com/software

Install the Raspberry Pi Imager

Run the downloaded file and follow the installation instructions.



Load the Raspberry Pi OS onto a Micro SD Card


Connect the target Micro SD Card

Connect the target Micro SD Card to a computer with the Raspberry Pi Imager installed.

Open the Raspberry Pi Imager

Windows 10:  Start | Raspberry Pi | Raspberry Pi Imager
Windows 11:  Start | All Apps | Raspberry Pi | Raspberry Pi Imager

Select the Desired Options

Raspberry Pi Device | CHOOSE DEVICE | <YourRaspberryPiModel> - Example:  Raspberry Pi 5
Operating System | CHOOSE OS | <DesiredRaspberryPiOS> - Example:  Raspberry Pi OS (64-bit)
Storage | CHOOSE STORAGE | Generic-SD/MMC USB Device
NEXT
EDIT SETTINGS |
  GENERAL |
    Set hostname:  | Checked  <DefineYourRaspberryHostnameHere> - Example:  Pi-0001
    Set username and password | Checked
      Username:  <DefineYourRaspberryPiUsernameHere> - Example:  Pi
      password:  <DefineYourRaspberryPiPasswordHere> - Example:  PiPassword
    Configure Wireless LAN | Not Checked
    Set local settings | Checked
      Time zone:  <SelectYourTimeZone> - Example:  America/Los_Angels
      Keyboard Layout:  <SelectYourKeyboardLayoutHere> - Example:  us
  SERVICES |
    Enable SSH | Checked (See "General Notes" 5. near the top of this document)
      Use password authentication | Selected
  OPIONS |
    Play sound when finished | Not Checked
    Eject media when finished | Checked
    OPIONS | Eject telemetry | Checked
  SAVE
Would you like to apply OS customizations Settings? | YES
All existing data on 'Generic-SD/MMC USB Device' will be erased.  Are you sure you want to continue? | YES
When the message "You can now remove the SD card from the reader" is displayed | CONTINUE
Remove the Micro SD card from the reader.



Insert the Micro SD Card into the Target Raspberry Pi


Be certain the Target Raspberry Pi is powered off.
Insert the Micro SD Card loaded with the Raspberry Pi OS into the target Raspberry Pi 5, 4 or 3.  Note:  It inserts up-side-down (contacts up) into the Raspberry Pi.
Power on the Raspberry Pi
It is typical for the Raspberry Pi to reboot two or three times the first time it is powered up before it is ready for its first use.  This often takes three to five minutes.



Locate the target Raspberry Pi IP Address


Use a tool such as Advanced IP Scanner to locate the DHCP assigned IP Address of the Raspberry Pi.
https://www.advanced-ip-scanner.com

  - or -

Connect directly to the target Raspberry Pi via a Display, Keyboard and Mouse.
Open a Terminal window.
sudo hostname -I



Connect to the target Raspberry Pi


Use SSH via a tool such as PuTTY to connect to the Raspberry Pi.
https://www.putty.org
Connect using the IP address or URL of the target Raspberry Pi.
Note:  The first time a connection is made, a security warning may be displayed | Yes

  - or -

Connect directly to the target Raspberry Pi via a Display, Keyboard and Mouse, then open a Terminal window.



Check and update the Raspberry Pi 4 or Pi 5 EEPROM Version

Note:  This tool only works with Raspberry Pi 4 or Pi 5.  Raspberry Pi 3B+ and below have a ROM that can not be updated.

Check if the Raspberry Pi 4 or Pi 5 EEPROM should be updated

sudo rpi-eeprom-update -a

Update the Raspberry Pi 4 or Pi 5 EEPROM if required.

sudo raspi-config
Advance Options | Bootloader Version | Latest | Yes



Install and configure TeamViewer

See "General Notes" 5. near the top of this document.


Install TeamViewer


Download latest package lists

sudo apt-get update -y

Download and install updated listed packages

sudo apt-get upgrade -y

Disable Wayland (Remote Graphics Support) and switch to the older X11 (Remote Graphics Support) because TeamViewer does not yet work with Wayland (Note:  Wayland in not enabled on Raspberry Pi OS (Legacy) by default)

sudo raspi-config
Advance Options | [Enter] | Wayland | [Enter] | X11 | [Enter] | Ok | [Enter] | Finish | [Enter] | Would you like to reboot now? | Yes | [Enter]

Download and install TeamViewer - Select one of the four configurations below:




1)  TeamViewer Full Client instalation with a 64-Bit OS:


  Download TeamViewer

  wget https://download.teamviewer.com/download/linux/teamviewer_arm64.deb

  Install TeamViewer (Note:  Errors during installation are normal and can usually be ignored)

  sudo dpkg -i teamviewer_arm64.deb



2)  TeamViewer Full Client instalation with a 32-Bit OS:


  Download TeamViewer

  wget https://download.teamviewer.com/download/linux/teamviewer_armhf.deb

  Install TeamViewer (Note:  Errors during installation are normal and can usually be ignored)

  sudo dpkg -i teamviewer_armhf.deb



3)  TeamViewer Host instalation with a 64-Bit OS:


  Download TeamViewer

  wget https://download.teamviewer.com/download/linux/teamviewer-host_arm64.deb

  Install TeamViewer (Note:  Errors during installation are normal and can usually be ignored)

  sudo dpkg -i teamviewer-host_arm64.deb



4)  TeamViewer Host instalation with a 32-Bit OS:


  Download TeamViewer

  wget https://download.teamviewer.com/download/linux/teamviewer-host_armhf.deb

  Install TeamViewer (Note:  Errors during installation are normal and can usually be ignored)

  sudo dpkg -i teamviewer-host_armhf.deb



Download and install additional OS compnents needed by TeamViewer - This corrects for the errors above, if any.

sudo apt --fix-broken install -y

Download latest package lists

sudo apt-get update -y

Download and install updated listed packages

sudo apt-get upgrade -y


Configure TeamViewer


Set the TeamViewer password

sudo teamviewer passwd <DefineYourTeamViewerPasswordHere> - Example:  sudo teamviewer passwd MyTeamViewerPassword

Accept TeamViewer Licensing only, but do no additional configuration from this setup tool

sudo teamviewer setup
Are you a resident of the Republic of Korea? (y/n) | n
Accept License Agreement? (y/n) | y
Abort the TeamViewer setup at this poit by pressing Control-C (Pressing the "Control" key and "C" key at the same time).

Obtain and record the TeamViewer ID (Note:  This only only provides the TeamViewer ID if it is connected to the Internet)

sudo teamviewer info
The TeamViewer ID is displayed twice near the top of the TeamViewer information.  Record the TeamViewer ID for you records.

Reboot the Raspberry Pi to get TeamViewer working.  Note:  "sudo teamviewer --daemon restart" or "sudo systemctl restart teamviewerd" do not get TeamViewer working

sudo reboot

Set TeamViewer to accept incoming LAN connections:


Since TeamViewer should now be working, a connection to the Raspberry Pi GUI should be possible via the TeamViewer client by using the TeamViewer ID of the target Raspberry Pi, obtained above.

Using TeamViewer from another machine, connect to the Raspberry Pi using the IP address or URL of the target Raspberry Pi.
  - or -
Connect directly to the target Raspberry Pi via a Display, Keyboard and Mouse, then open a Terminal window.

From the Raspberry Pi GUI open TeamViewer by clicking on the TeamViewer icon in the right side of the Task Bar at the top of the Raspberry Pi desktop.

Click on "Extras" in the left side of the TeamViewer Menu Bar at the top of the TeamViewer window.

Click on "Options".  It opens to the "General" window.

In the "General" window, click on the "Incoming LAN connections" drop down list and select "accept".

Click on the "OK" button.

Close the TeamViewer window by clicking on the X in the upper right hand corner of the TeamViewer window.



Connect to the traget Raspberry Pi via TeamViewer


Use TeamViewer to connect to the Raspberry Pi

https://www.teamviewer.com
Connect using the TeamViewer ID, IP address or URL of the target Raspbery Pi.



Configure and Enable VNC

See "General Notes" 5. near the top of this document.

Set VNC Display Resolution and Enable VNC

sudo raspi-config
Interface Options | VNC | Yes | OK | Display Options | VNC Resolution | 1024x768 | OK | Finish | Yes (Reboot required for Raspbery 4 and 5)

  - or -

Via the Rasberry Pi GUI (Desktop)
Click on "Start" (Rasberry) in the left side of the Task Bar at the top of the Raspberry Pi desktop
Click on "Preferences"
Click on "Raspberry Pi Configuration"
Click on the "Interfaces" tab.
Click on the "VNC:" switch to turn it on.
Click on the "Display" tab
Click on the "Headless Resolution:" drop-down list and select "1024x768"
Click on the "OK" Button.
Reboot required for Raspbery Pi 4 and 5.  Click on the "OK" Button when this is displayed:  "The changes you have made require the Raspberry Pi to be rebooted to take effect.  Would you like to reboot now? | Yes"



Connect to the traget Raspberry Pi via VNC


Use a tool such as RealNVC Viewer to connect to the Raspberry Pi

https://www.realvnc.com
  - or -
https://www.realvnc.com/en/connect/download/combined
Connect using the IP address or URL of the target Raspbery Pi.
Note:  The first time a connection is made, a security warning may be displayed | Continue



Install and configure the Webserver - Apache 2

See "General Notes" 7. near the top of this document.


Install the Apache 2 Webserver


Download latest package lists

sudo apt-get update -y

Download and install updated listed packages

sudo apt-get upgrade -y

Download and install Apache

sudo apt install apache2 -y


Test the Apache 2 Webserver (Optional)


Get the Apache2 version

sudo apache2ctl -v

View the Apache2 default website

Type the IP Address of the Raspberry Pi webserver into the browser of a device connected to the same network as the Raspberry Pi webserver.  The Apache2 default website should be displayed.


Configure the Apache 2 Webserver


Set Up Virtual Hosts (Webservers)

Apache 2 supports one or more Virtual Hosts on a single machine.  In the example below, three (3) Virtual Hosts are being setup and configured:
  exampledomain1.com
  exampledomain2.com
  exampledomain3.com

Create directories to hold the website files for each of the websites to be hosted

sudo mkdir -p /var/www/<ExampleWebDomainNameURL1>/html/ - Example:  sudo mkdir -p /var/www/exampledomain1.com/html/
sudo mkdir -p /var/www/<ExampleWebDomainNameURL2>/html/ - Example:  sudo mkdir -p /var/www/exampledomain2.com/html/
sudo mkdir -p /var/www/<ExampleWebDomainNameURL3>/html/ - Example:  sudo mkdir -p /var/www/exampledomain3.com/html/

Change the ownership for the general web directory /var/www and its contents so pages can be uploaded, downloaded and served correctly

sudo chown -R pi:pi /var/www

Change the permissions for the general web directory /var/www and its contents so pages can be uploaded, downloaded and served correctly

sudo chmod -R 755 /var/www

Create Virtual Host Configuration files for each website to be hosted by copying the Default Virtual Host Configuration file


sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/<ExampleWebDomainNameURL1>.conf - Example:  sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/exampledomain1.com.conf

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/<ExampleWebDomainNameURL2>.conf - Example:  sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/exampledomain2.com.conf

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/<ExampleWebDomainNameURL3>.conf - Example:  sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/exampledomain3.com.conf


Edit each of the New Virtual Host Files updating the entries as follows


ExampleWebDomainNameURL1 - Example:  exampledomain1.com (the file to be edited would be exampledomain1.com.conf)


Start Mousepad from Terminal in the Raspberry Pi GUI (Desktop):  sudo mousepad /etc/apache2/sites-available/<ExampleWebDomainNameURL1>.conf - Example:  sudo mousepad /etc/apache2/sites-available/exampledomain1.com.conf
  - or -
SSH or Terminal:  sudo nano /etc/apache2/sites-available/<ExampleWebDomainNameURL1>.conf - Example:  sudo nano /etc/apache2/sites-available/exampledomain1.com.conf

Replace:
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html
With:
  ServerAdmin <YourEMailAddress> - Example:  ServerAdmin example@gmail.com
  ServerName <ExampleWebDomainNameURL1> - Example:  ServerName exampledomain1.com
  ServerAlias www.<ExampleWebDomainNameURL1> - Example:  ServerAlias www.exampledomain1.com
  DocumentRoot /var/www/<ExampleWebDomainNameURL1>/html - Example:  DocumentRoot /var/www/exampledomain1.com/html

Save and close mousepad (File| Save [Ctrl+S] and File | Quit [Ctrl+Q or X out])
  - or -
Save and close nano (Press CTRL + X and then press y and ENTER to save changes)


ExampleWebDomainNameURL2 - Example:  exampledomain2.com (the file to be edited would be exampledomain2.com.conf)


Start Mousepad from Terminal in the Raspberry Pi GUI (Desktop):  sudo mousepad /etc/apache2/sites-available/<ExampleWebDomainNameURL2>.conf - Example:  sudo mousepad /etc/apache2/sites-available/exampledomain2.com.conf
  - or -
SSH or Terminal:  sudo nano /etc/apache2/sites-available/<ExampleWebDomainNameURL2>.conf

Replace:
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html
With:
  ServerAdmin <YourEMailAddress> - Example:  ServerAdmin example@gmail.com
  ServerName <ExampleWebDomainNameURL2> - Example:  ServerName exampledomain2.com
  ServerAlias www.<ExampleWebDomainNameURL2> - Example:  ServerAlias www.exampledomain2.com
  DocumentRoot /var/www/<ExampleWebDomainNameURL2>/html - Example:  DocumentRoot /var/www/exampledomain2.com/html

Save and close mousepad (File| Save [Ctrl+S] and File | Quit [Ctrl+Q or X out])
  - or -
Save and close nano (Press CTRL + X and then press y and ENTER to save changes)


ExampleWebDomainNameURL3 - Example:  exampledomain3.com (the file to be edited would be exampledomain3.com.conf)


Start Mousepad from Terminal in the Raspberry Pi GUI (Desktop):  sudo mousepad /etc/apache2/sites-available/<ExampleWebDomainNameURL3>.conf - Example:  sudo mousepad /etc/apache2/sites-available/exampledomain2.com.conf
  - or -
SSH or Terminal:  sudo nano /etc/apache2/sites-available<ExampleWebDomainNameURL3>.conf

Replace:
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html
With:
  ServerAdmin <YourEMailAddress> - Example:  ServerAdmin example@gmail.com
  ServerName <ExampleWebDomainNameURL3> - Example:  ServerName exampledomain3.com
  ServerAlias www.<ExampleWebDomainNameURL3> - Example:  ServerAlias www.exampledomain3.com
  DocumentRoot /var/www/<ExampleWebDomainNameURL3>/html - Example:  DocumentRoot /var/www/exampledomain3.com/html

Save and close mousepad (File| Save [Ctrl+S] and File | Quit [Ctrl+Q or X out])
  - or -
Save and close nano (Press CTRL + X and then press y and ENTER to save changes)


Enable the New Virtual Hosts

sudo a2ensite <ExampleWebDomainNameURL1>.conf - Example:  sudo a2ensite exampledomain1.com.conf
sudo a2ensite <ExampleWebDomainNameURL2>.conf - Example:  sudo a2ensite exampledomain2.com.conf
sudo a2ensite <ExampleWebDomainNameURL3>.conf - Example:  sudo a2ensite exampledomain3.com.conf

Reload the Apache 2 Webserver

sudo systemctl reload apache2

Note

If a site needs to be edited again, disable the site before editing it using the a2dissite command with a syntax similar to the a2ensite command above.  After editing the site, save the changes and enable the site again using the a2ensite command as mentioned above, then reload Apache for it to get and begin using the new configuration.



Install and configure the FTP server - VSFTP

See "General Notes" 5. near the top of this document.


Install the VSFTP FTP server


Download latest package lists

sudo apt-get update -y

Download and install updated listed packages

sudo apt-get upgrade -y

Download and install VSFTP

sudo apt install vsftpd


Configure the VSFTP FTP server


Edit vsftpd configuration file as follows

Start Mousepad from Terminal in the GUI (Desktop):  sudo mousepad /etc/vsftpd.conf
  - or -
SSH or Terminal:  sudo nano /etc/vsftpd.conf

Uncomment:  #write_enable=YES  →  write_enable=YES
Uncomment:  #local_umask=022  →  local_umask=022
Add this line to bottom of the file:  local_root=/var/www

Save and close mousepad (File| Save [Ctrl+S] and File | Quit [Ctrl+Q or X out])
  - or -
Save and close nano (Press CTRL + X and then press y and ENTER to save changes)

Restart the VSFTP FTP server

sudo systemctl restart vsftpd



Connect to the traget Raspberry Pi via FTP


Use a tool such as FileZilla to connect to the Raspberry Pi

https://filezilla-project.org
Connect using the IP address or URL of the target Raspbery Pi.



Change the Raspberry Pi IP address and network settings using NetworkManager




Enable NetworkManager on Raspberry Pi OS (Legacy).  NetworkManager is already enabled by default on Raspberry Pi OS.


  Enable NetworkManager

  sudo raspi-config
  Advance Options | [Enter] | Network Config | [Enter] | NetworkManager | [Enter] | OK | [Enter] | Finish | [Enter] | Would you like to reboot now? | Yes | [Enter]
  Note 1:  The DHCP assigned IP Address of the Raspberry Pi will likely change and may need to be located again.
  Note 2:  The TeamViewer ID of the Raspberry Pi will likely change and may need to be obtained again.



Change the Raspberry Pi IP address and network settings using the NetworkManager User Interface (UI)

sudo nmtui
Edit a connection | [Enter] | Wired Connection 1 | [Enter]
Change these fields  (Note:  Use [Tab] to move around the window, [Enter] to select, and [Esc] to back out of a window):
  IPv4 CONFIURATION | <Automatic> | [Enter] | Manual | [Enter] | <Show> | [Enter]
  Addresses | <Add...> | [Enter] | <YourRaspberryPiIPAddress>/<YourNetworkSubnetworkMask> - Example:  192.168.0.25/24) | [Enter]
    (Note:  The Subnetwork Mask is expressed in Slash Notation along with the IP Address. - See the CLI section below for additional information)
  Gateway | <YourNetworkDefaultGatewayIPAddress> (Typicaly the network router LAN IP Address - Example:  192.168.0.1 | [Enter]
  DNS Servers | <Add...> | [Enter] | <DNSServer1> - Example:  8.8.8.8 | [Enter]
  DNS Servers | <Add...> | [Enter] | <DNSServer2> - Example:  8.8.4.4 | [Enter]
  OK | [Enter]  (Note:  [Tab] to bottom of the window)
[Esc] | [Esc]

Restart the connection to to begin using the new settings

sudo nmcli con up "Wired connection 1"


- or -


Change the Raspberry Pi IP address and network settings using NetworkManager Command Line Interface (CLI)

Show all network connections

sudo nmcli con show
Note:  "Wired connection 1" is the default Eternet connection name and is assumed in the following commands.


Set IP Address

sudo nmcli con mod "Wired connection 1" ipv4.addresses <YourRaspberryPiIPAddress>/<YourNetworkSubnetworkMask> - Example:  sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.0.25/24
Note:  The Subnetwork Mask is expressed in Slash Notation along with the IP Address.

Network Subnetwork Mask and Slash Notation Relationships:
Class  Mask                      Slash  Addresses  Nodes
A255.000.000.000/81677721616777214
B255.255.000.000/166553665534
B255.255.128.000/173276832766
B255.255.192.000/181638416382
B255.255.224.000/1981928190
B255.255.240.000/2040964094
B255.255.248.000/2120482046
B255.255.252.000/2210241022
B255.255.254.000/23512510
C255.255.255.000/24256254
C255.255.255.128/25128126
C255.255.255.192/266462
C255.255.255.224/273230
C255.255.255.240/281614
C255.255.255.248/2986
C255.255.255.252/3042
C255.255.255.254/3120
C255.255.255.255/3210

Set the Gateway Address

Note:  Typicaly the Gateway Address is network router LAN IP Address
sudo nmcli con mod "Wired connection 1" ipv4.gateway <YourNetworkDefaultGatewayIPAddress> - Example:  sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.0.1

Set theDNS Servers

sudo nmcli con mod "Wired connection 1" ipv4.dns "<DNSServer1> <DNSServer2> <DNSServer...>" - Example:  sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4"

Set the Addressing Mode to Manual (Static)

sudo nmcli con mod "Wired connection 1" ipv4.method manual

Restart the connection to to begin using the new settings

sudo nmcli con up "Wired connection 1"

For testing (Optional) - Display the IP Address.  Gateway.  DNS Servers and Addressing Mode

sudo nmcli -g ip4.address,ipv4.gateway,ip4.dns,ipv4.method connection show "Wired connection 1"

For testing (Optional) - Display the profile so all parameters can be reviewed

sudo nmcli -p con show "Wired connection 1"



Setup HTTPS using Let's Encrypt Certificates and Certbot

See "General Notes" 6. and 7. near the top of this document.


Install the snap Package Manager


Download latest package list

sudo apt-get update -y

Download and install updated listed packages

sudo apt-get upgrade -y

Download and install snapd

sudo apt install snapd

Reboot the Pi to get snap working

sudo reboot

Download and install the core snap in order to get the latest snapd

sudo snap install core
Note:  Some snaps require new snapd features and will show an error such as snap "lxd" assumes unsupported features" during install.  You can solve this issue by making sure the core snap is installed (sudo snap install core) and it’s the latest version (sudo snap refresh core).


Install Certbot - Certificate Fetcher for Let’s Encrypt


Remove certbot-auto and any Certbot OS packages from the apt package manager

sudo apt-get remove certbot

Install Certbot

sudo snap install --classic certbot

Prepare the Certbot command

sudo ln -s /snap/bin/certbot /usr/bin/certbot
Note:  Some snaps require new snapd features and will show an error such as snap "lxd" assumes unsupported features" during install.  You can solve this issue by making sure the core snap is installed (snap install core) and it’s the latest version (snap refresh core).


Configure Certbot, get certificats from Let’s Encrypt and autmaticaly configure apache for HTTPS

Note:  For this command to succeed, the Domain Name must already be setup in a public DNS server with either A or CNAME record pointing to the public IP Address of the target Raspberry Pi Webserver.  Alternatively, a host name setup in a DDNS server will work as well  (See "General Notes" 2. near the top of this document).

Get and install certificates, edit apache configuration files automatically, and turn on HTTPS access

sudo certbot --apache

Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): | <YourEMailAddress> - Example:  example@gmail.com

Terms of Service... Do you agree? | y

Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot | y

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: exampledomain1.com
2: www.exampledomain1.com
3: exampledomain1.com
4: www.exampledomain1.com
5: exampledomain1.com
6: www.exampledomain1.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): | [Enter]


Test Certbot


Test automatic renewal

sudo certbot renew --dry-run



Remove packages that were automatically installed and are no longer required

Occasionally excess update, upgrade and installation packages install automatically, but are no longer required and can be removed automatically.

Automatically detect and remove packages no longer required

sudo apt autoremove -y



Charles Varvayanis
Sonora, CA  95370
e-mail:  charles@varvayanis.com
Phone:  (209) 586-3782
Fax:  (209) 586-3761
Business Card (PDF 153 KB) PDF
www.varvayanis.com
www.varvayanis.com

© 2024 Charles Varvayanis.  All rights reserved.